// pages/custom/detail/detail.js
var app = getApp();
var allpicurls;
Page({

  /**
   * 页面的初始数据
   */
  data: {
  
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    wx.getSystemInfo({
      success: function (res) {
        var temval = res.windowWidth - 20;
        temval = temval / 4;
        that.setData({
          picwh: temval
        });
      },
    });
    this.loadDetail(options.tuid);
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }, 
  showPic: function (e) {
    var itempics = e.currentTarget.dataset.itempics;
    var imgurl = e.currentTarget.dataset.curpic;
    wx.previewImage({
      urls: itempics,
      current: imgurl
    });
  },
  loadDetail:function(tuid){
    var url = app.globalData.webUrl + '/index.php/api/Custom/getUserCustomMsg';
    var params = {
      tuid: tuid
    };
    app.loadDataFromServer(url,this.loadDetailCallBack,params);
  },
  loadDetailCallBack:function(res){
    console.log(res);
    var conditions = [];
    for (var i = 0; i < res.result.att.length; i++){
      if (res.result.att[i].tp == 2){
        var pics = res.result.att[i].attvalue.split(',');
        for(var j=0;j<pics.length;j++){
          pics[j] = app.globalData.webUrl + '/' + pics[j];
        }
        res.result.att[i].pics = pics;
      }
      conditions.push(res.result.att[i]);
    }
    this.setData({
      info: res.result.info,
      conditions: conditions
    });
  }
})